package com.jlrdb.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.jlrdb.DAO.CellularBroadcastDAO;
import com.jlrdb.DAO.CellularBroadcastDAOImpl;
import com.jlrdb.model.CellularBroadcast;
import com.jlrdb.model.CellularBroadcasts;

public class CellularBroadcastService {
	CellularBroadcastDAO cellularBroadcastDAO = new CellularBroadcastDAOImpl();

	public int addCellularBroadcast(CellularBroadcast cellularBroadcast) {
		int result = cellularBroadcastDAO.addCellularBroadcast(cellularBroadcast);
		return result;
	}

	public CellularBroadcast checkEmptyValues(CellularBroadcast cellularBroadcast) {
		if (cellularBroadcast.getAditional_Contacts().length() == 0)
			cellularBroadcast.setAditional_Contacts("--");
		if (cellularBroadcast.getOperators().length() == 0)
			cellularBroadcast.setOperators("Not Known");
		if (cellularBroadcast.getData_Enhancement_Technology().length() == 0)
			cellularBroadcast.setData_Enhancement_Technology("Not Known");
		if (cellularBroadcast.getEnd_Date().length() == 0)
			cellularBroadcast.setEnd_Date("Not Known");
		if (cellularBroadcast.getFrequency_Spectrum().length() == 0)
			cellularBroadcast.setFrequency_Spectrum("Not Known");
		if (cellularBroadcast.getIndustry_Regulators().length() == 0)
			cellularBroadcast.setIndustry_Regulators("Not Known");
		if (cellularBroadcast.getInformation_Transfer_Rate().length() == 0)
			cellularBroadcast.setInformation_Transfer_Rate("Not Known");
		// if (cellularBroadcast.getMarket_Confirmation().length()==0)
		// cellularBroadcast.setMarket_Confirmation("Not Known");
		if (cellularBroadcast.getMarket_Penetration().length() == 0)
			cellularBroadcast.setMarket_Penetration("Not Known");
		if (cellularBroadcast.getNotes().length() == 0)
			cellularBroadcast.setNotes("--");
		if (cellularBroadcast.getProblems().length() == 0)
			cellularBroadcast.setProblems("Not Known");
		if (cellularBroadcast.getSource_Of_Reference().length() == 0)
			cellularBroadcast.setSource_Of_Reference("--");
		if (cellularBroadcast.getStart_Date().length() == 0)
			cellularBroadcast.setStart_Date("Not Known");
		if (cellularBroadcast.getLast_Date_Verified() == null)
		{
			DateFormat df = new SimpleDateFormat("dd/MM/yy");
			String formattedDate = df.format(new Date());
			cellularBroadcast.setLast_Date_Verified(formattedDate);
		}
		return cellularBroadcast;
	}

	public CellularBroadcast getThisBroadcast(long broadcastId) {
		CellularBroadcast cellularBroadcast = new CellularBroadcast();
		cellularBroadcast = cellularBroadcastDAO.getThisBroadcast(broadcastId);
		return cellularBroadcast;
	}

	public int updateCellularBroadcast(CellularBroadcast cellularBroadcast, long broadcastId) {
		int result = cellularBroadcastDAO.updateCellularBroadcast(cellularBroadcast, broadcastId);
		return result;
	}

	public CellularBroadcasts viewCellularBroadcasts(CellularBroadcast cellularQuery) {
		CellularBroadcasts cellularBroadcasts = new CellularBroadcasts();
		cellularBroadcasts = cellularBroadcastDAO.viewCellularBroadcasts(cellularQuery);
		return cellularBroadcasts;
	}
}
